import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import zhCn from 'element-plus/es/locale/lang/zh-cn'
import axios from 'axios'
// import ECharts from 'vue-echarts'
// import 'echarts'

// 导入全局样式表
import './assets/css/global.css'
const app = createApp(App)
// 配置请求根路径
axios.defaults.baseURL = 'http://localhost:8080/api'
app.config.globalProperties.axios = axios
// // 请求在到达服务器之前，先会调用use中的这个回调函数来添加请求头信息
// axios.interceptors.request.use(config => {
//   const userInfo = JSON.parse(sessionStorage.getItem('userInfo'))
//   // 为请求头对象，添加token令牌验证的Authorization字段
//   config.headers.Authorization = userInfo ? userInfo.token : ''
//   return config
// })
// console.log(sessionStorage.getItem('userInfo'))
axios.interceptors.request.use(function (config) {
  // 在发送请求之前做些什么
  const userInfo = JSON.parse(sessionStorage.getItem('userInfo'))
  config.headers.Authorization = userInfo ? userInfo.token : ''
  return config
})
// 全局注册el-icon
for (const [name, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(name, component)
}
app.use(store)
  .use(router)
  .use(ElementPlus, { locale: zhCn })
  // .component('Echarts', ECharts)
  // .use(ElementPlusIconsVue)
  .mount('#app')
